<template>
  <view class="main">
	 <view class="part1">
	   <view class="part2">
		<view class="part2-1">
		 拍手认证-个人信息
		 <view class="ptxt1">{{ptxt1}}</view>
		</view> 
		<view class="part2-2">
		  <view class="ptxt2">{{ptxt}}</view>
		  <image src="https://ppp.new.zeroitem.cn/ppp/add.png" class="pimg30" @click="uploadvideo"></image>
	    </view> 
	   </view>
	  <view class="part3">
		  
		 <view class="part3-1">
		    <view class="p1">拍手姓名</view>
			<view class="p2">
		      <input type="text" placeholder="请填写您的真实姓名" class="cinput" v-model="xm"/>
			</view>
		 </view> 

		 <view class="part3-1">
		    <view class="p1">联系电话</view>
			<view class="p2">
		      <input type="text" placeholder="请输入联系电话" class="cinput" v-model="phone"/>
			</view>
		 </view> 			 

	  </view>		 
	 </view>  
	 <view class="part4">
		<view class="part4-1">
		 请输入个人简介
		</view>
		<textarea class="ptxt" v-model="desc" placeholder="字数限制300字以内,字数需大于50个字"></textarea>
		<view class="btn" @click="submitorder">确认提交</view>
	 </view>
  </view>
</template>

<script>
	import {
		mapGetters,
		mapActions
	} from 'vuex'
	import {
		toLogin
	} from '@/utils/login'
	
	import {
		loadingFun,
		menuJump
	} from '@/utils/tools'	
    import {
	  psrz,psrzinfo
	} from '@/api/ppp'	
    import {
		loadingType
	} from '@/utils/type'
	
    import {
	  uploadFileToTencentClound
	} from '@/js_sdk/COS'
   
	const app = getApp()
	export default {
		data() {
			return {
		     desc:"",
			 xm:"",
			 phone:"",
			 ptxt:"请添加专业证书或者资质文件图片",
			 ptxt1:"待上传",
			 vsrc:"",
			 from:""
           }
		},
		onLoad(options) {
		 if(options.from!='' && options.from!=undefined){
		  this.from='menu' 
		 }
		 this.psrzinfo();
		},
		onShow() {

		},

		onReachBottom() {
	    
		},
		onPullDownRefresh() {

		},

		methods: {
		async submitorder(){
		 var that=this;
		 var xm=this.xm;
		 var phone=this.phone;
		 var desc=this.desc;
		 var vname=this.ptxt;
		 if(xm=='' || xm==undefined){
		  uni.showToast({title:"请填写您的真实姓名",icon:"none"}); 
		  return false;
		 }
		 if(phone=='' || phone==undefined){
		  uni.showToast({title:"请填写您的联系电话",icon:"none"}); 
		  return false;
		 }	
		 if(desc=='' || desc==undefined){
			uni.showToast({title:"请填写您的个人简介",icon:"none"}); 
			return false;
		 }	
		 if(desc.length<50){
			uni.showToast({title:"简介字数太少了，50个字以上",icon:"none"});
			return false; 
		 }
		 if(vname=='请添加专业证书或者资质文件图片'){
			vname="";
		 }	
	
			var odata={
				xm:xm,phone:phone,
				desc:desc,vname:vname,
				part:"pxinfo"
			}; 
	       const{
				code,
				msg,
				data,
			  }= await psrz(odata);
			  if(code==1){
				if(that.from=='menu'){
					uni.navigateTo({
						url:"/pages/ppp/ps/menu"
					}) 
				}else{
				uni.navigateTo({
					url:"/pages/ppp/ps/psrz"
				})  
				}
			  }		 
		},
		async psrzinfo(){
		  var that=this;
		  const{
		  	code,
		  	msg,
		  	data,
		   }= await psrzinfo();
		   if(code==1 && data!=null){
		     var pxinfo=data.pxinfo;
			 that.xm=data.xm;
			 that.phone=data.phone;
			 that.desc=pxinfo.desc;
			 if(pxinfo.vname!='' &&  pxinfo.vname!=undefined){
			   that.ptxt1='已上传';
			   that.vsrc='https://ppp-1300934138.cos.ap-shanghai.myqcloud.com/wxFile/'+pxinfo.vname;
			   that.ptxt=pxinfo.vname;
			 }
		   }	
		},
      uploadvideo(){
			var that=this;
			uni.chooseImage({
				sourceType: ['camera', 'album'],
				success: function (res) {
	              const tempFilePaths = res.tempFilePaths;
				  var filePath=tempFilePaths[0];
				  let ext = filePath.substr(filePath.lastIndexOf('.') + 1);
				  var timestamp = (new Date()).valueOf();
				  var filename=timestamp+"."+ext;
				  uploadFileToTencentClound(filename,filePath).then((res1)=>{
			        that.vsrc='http://ppp-1300934138.cos.ap-shanghai.myqcloud.com/wxFile/'+filename;
					that.ptxt=filename;
				    that.ptxt1='已上传';
				  })
				 }
		    });  
		  },		   
		},
		computed: {
			...mapGetters(['isLogin']),
		}
	}
</script>
<style>
 @import "./psinfo.css";	
</style>
